package register;

import com.xiguanlezz.cn.client.env.NacosClientProperties;
import org.junit.Assert;
import org.junit.Test;

import java.util.Properties;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/18 23:16
 * @Description：
 */
public class _2_配置信息封装 {

    @Test
    public void configOrderFromNacosClientProperties() {
        Properties properties = new Properties();
        properties.setProperty("nacos.address", "127.0.0.1:8848(properties)");
        NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
        Assert.assertEquals("127.0.0.1:8848(properties)", nacosClientProperties.getProperty("nacos.address"));
        properties.remove("nacos.address");
        nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
        Assert.assertEquals("127.0.0.1:8848(jvm)", nacosClientProperties.getProperty("nacos.address"));
    }

    @Test
    public void configValueTypeConvert() {
        Properties properties = new Properties();
        properties.setProperty("intVal", "8888");
        properties.setProperty("booleanVal", "true");
        properties.setProperty("longVal", String.valueOf(Long.MAX_VALUE));
        NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
        Assert.assertEquals(new Integer(8888), nacosClientProperties.getInteger("intVal"));
        Assert.assertEquals(Boolean.TRUE, nacosClientProperties.getBoolean("booleanVal"));
        Assert.assertEquals(new Long(Long.MAX_VALUE), nacosClientProperties.getLong("longVal"));
    }
}
